
//1.导入依赖
import http from '@/utils/http/index'
import { UploadFile } from "element-plus"

//2.定义类型 (请求参数类型 | 返回数据类型)
//参数类型
interface ApartmentParamType {
    current:number,
    size:number,
    provinceId?:number,
    cityId?:number,
    districtId?:number
}

// 分页数据的结构
interface PageResData<T> {
    records: T[]
    // 当前页
    current?: number
    // 每页显示条数
    size?: number
    total: number
  }

//公寓类型
// 添加修改和详情共用
interface ApartmentData {
    id?: number | string
    name: string
    introduction: string
    districtId: number | string
    districtName?: string
    cityId: number | string
    cityName?: string
    provinceId: number | string
    provinceName?: string
    addressDetail: string
    latitude?: number | string
    longitude?: number | string
    phone: string
    isRelease?: string | number | any
    totalRoomCount?: number
    freeRoomCount?: number
    // 	公寓配套id
    facilityInfoIds?: number[]
    // 	公寓配套信息
    facilityInfoList?: []
    // 	公寓标签id
    labelIds?: number[]
    // 公寓标签信息
    labelInfoList?: []
    // // 	公寓杂费值id
    feeValueIds?: number[]
    // // 	公寓杂费值信息
    feeValueVoList?: []
    // 图片信息 上传和修改详情的图片详情不同
    graphVoList?:
      {
          url: string
          name: number
      }[]
      | UploadFile[]
  }


//3.请求的api方法 
let getApartmentList= (queryVo:ApartmentParamType)=>{
    return http.get<PageResData<ApartmentData>>('/admin/apartment/pageItem',queryVo);
}


//4.删除的api方法
let removeApartmentById=(id:number|string)=>{
    return http.delete(`/admin/apartment/removeById?id=${id}`);
}




let saveOrUpdateApartment=(apartment:ApartmentData)=>{
    return http.post('/admin/apartment/saveOrUpdate',apartment);
}


//4. 对外导出
export {
    type ApartmentParamType,
    type ApartmentData,
    type PageResData,
    getApartmentList,
    removeApartmentById,
    saveOrUpdateApartment
}